package com.cosina.game.crystallight.model.crystal;

import com.cosina.game.crystallight.data.CrystalInfo;
import com.cosina.game.crystallight.engine.BattleEngine;

public class CrystalFactory {
	public static Crystal create(int color){
		int currentMana = BattleEngine.manaFlask.getCurrent();
		int index = getCanCreateLevelInfoIndex(currentMana);
		if(index == -1){
			throw new IllegalStateException("mana too low to create crystal! currentMana :" + currentMana);
		}
		BattleEngine.manaFlask.used(CrystalInfo.manaRequired[index][1]);
		return new 	Crystal(color,CrystalInfo.manaRequired[index][2]);
	}

	private static int getCanCreateLevelInfoIndex(int currentMana) {
		for(int i=0; i<CrystalInfo.manaRequired.length; i++){
			if(currentMana >= CrystalInfo.manaRequired[i][0]){
				return i;
			}
		}
		return -1;
	}
}
